import React, { PureComponent } from "react";
import { View } from "react-native";
import { Button, Text, Input } from "react-native-tengits-elements";
// import Controller from "../libs/SerialPortController";
import SerialPortManager from "../logic/SerialPortManager"
import {SerialConfig} from "../logic/LogicConstant"

export default class Rs485TestPage extends React.PureComponent {
    constructor() {
        super();
        this.state = {
            result: ""
        }
    }

    render() {
        const{ip, port, userName, pwd} = this.state;
        return <View style={{flex:1, backgroundColor:'white', padding:30, justifyContent:'space-around'}}>
                <View style={{flexDirection:'column'}}>
                    <Input
                        placeholder='result'
                        defaultValue={this.state.result}
                        onChangeText={value => this.setState({ result: value })}
                    />
                </View>
                <Button
                    title="打开设备"
                    onPress={async()=>{
                        let result = await SerialPortManager.createLoopController(SerialConfig.path, SerialConfig.port);
                        // this.setState({
                        //     result:result
                        // })
                        // console.log("result:",result);
                    }}
                    />
                <Button
                    title="查询地址"
                    onPress={async()=>{
                    }} 
                    />
                <Button
                    title="设置亮度"
                    onPress={async()=>{
                        await SerialPortManager.controlLight(4, 100);
                    }}
                    />
        </View>
    }

}